/**
 * @description 代码均复制粘贴自 shb-paas-pc项目
 */

import http from '@src/util/http'

import { proxyMap, response } from '@src/api/config'

/**
 * @description 获取物流公司列表
 * @param {Object}
 */
export const getLogisticsCompanyList = async (params = {}) => {
  const listCache = localStorage.getItem('allLogisticsCompany');
  if (listCache) {
    // 有缓存 直接拿缓存的数据
    return JSON.parse(listCache);
  }
  const res = await http.get(
    `${proxyMap.workbench}/outside/logistics/courier-company/list`,
    params
  );
  const list = await response(res);
  localStorage.setItem('allLogisticsCompany', JSON.stringify(list));
  return list;
}

/**
 * 查询快递额度
 */
export const getLogisticsQuotaDetail = async (params = {}) => {
  const res = await http.get(
    `${proxyMap.workbench}/outside/logistics/quota/detail`,
    params
  );
  const data = await response(res);
  const {
    totalQuota,
    totalUse,
    isDailyLimit,
    dailyQuotaLimit,
    todayUse
  } = data;
  return totalUse < totalQuota && (!isDailyLimit || todayUse < dailyQuotaLimit);
}

export const getLogisticsDetail = async (params = {}) => {
  const res = await http.get(
    `${proxyMap.workbench}/outside/logistics/query`,
    params
  );
  return response(res);
}
